using UnityEngine;
using XLua;
using Yoozoo.Gameplay.RTS.Proto;

namespace Yoozoo.Gameplay.RTS
{
    public class ElementManager
    {
        
        public ElementManager()
        {
            
        }


        public void ShowSkillFocusEffect(long tid,TargetCoordinateType type)
        {
            var marchEntity = ArmyManager.Instance.MarchManager.GetMarchEntityByIdAndType(tid,type);
            if (marchEntity != null)
            {
                if (marchEntity.Hud != null)
                {
                    marchEntity.Hud.ShowSkillFocusEffect();
                }
            }
        }

        public void ShowReleaseSkillEffect(long tid,TargetCoordinateType type, int heroId, string skillName,int heroIndex,string monsterSkillIcon = null)
        {
            var marchEntity = ArmyManager.Instance.MarchManager.GetMarchEntityByIdAndType(tid,type);
            if (marchEntity!=null)
            {
                if (marchEntity.Hud!=null)
                {
                    marchEntity.Hud.ShowReleaseSkillEffect(heroId, skillName, heroIndex,monsterSkillIcon);
                }
                else
                {
#if DEVELOPMENT_BUILD || UNITY_EDITOR
                    Debug.LogError("ShowReleaseSkillEffect null");
#endif
                }
            }
            else
            {
#if DEVELOPMENT_BUILD || UNITY_EDITOR
                Debug.LogError("ShowReleaseSkillEffect null");
#endif
            }
        }

        public void ShowSkillHitEffect(long tid,TargetCoordinateType type,int team)
        {
            var marchEntity = ArmyManager.Instance.MarchManager.GetMarchEntityByIdAndType(tid,type);
            if (marchEntity != null)
            {
                if (marchEntity.Hud != null)
                {
                    marchEntity.Hud.ShowSkillHitEffect();
                }
                if (team == (int)MarchTeam.Self) //如果是自己的部队播放振屏幕
                {
                    if (CanShake(marchEntity.Position))
                    {
                        ArmyManager.Instance.ShakeScreen();
                    }
                }
                ArmyManager.Instance.GetRtsResourceManager().GetResourceById(1015);
            }
        }
        public void ShakeScreen()
        {
            if (!shakeEnabled)
            {
                return;
            }
            ArmyManager.Instance.ShakeScreen();
        }

        public void StopShake()
        {
            ArmyManager.Instance.StopShakeScreen();
        }

        public static bool shakeEnabled = true;

        public bool CanShake(Vector3 position)
        {
            if (!shakeEnabled)
            {
                return false;
            }
            var camera = WorldCameraManager.mainCamera;
            if (camera)
            {
                var screenPoint = camera.WorldToScreenPoint(position);
                return screenPoint.x >= 0 && screenPoint.x <= Screen.width && screenPoint.y >= 0 &&
                       screenPoint.y <= Screen.height;
            }
            return false;
        }

        [BlackList]
        public void Update()
        {
            
        }

        public void Dispose()
        {
        }
    }
}
